from enum import Enum
from pydantic import BaseModel
from typing import List, Optional


class BlockMode(str, Enum):
    WB = 'WB'
    WB_2G = 'WB + 2G'
    G2 = '2G'


class CarrierFrequencyFields(BaseModel):
    carrier_frequency_ul: float = 1_750_000_000
    carrier_frequency_dl: float = 1_850_000_000


class CarrierFrequency(BaseModel):
    enabled: bool = True
    fields: CarrierFrequencyFields = CarrierFrequencyFields()


class ConnectionType(str, Enum):
    EMPTY = ''
    RADIO = 'radio'
    OPTICS = 'optics'


class RelayChannelsFields(BaseModel):
    central_frequency_rx: float = 6_680_000_000
    central_frequency_tx: float = 7_020_000_000
    output_power: float = 18
    input_gain: float = 15
    output_gain: float = 50


class RelayChannels(BaseModel):
    enabled: Optional[bool] = False
    connection_type: Optional[ConnectionType] = ConnectionType.RADIO
    fields: RelayChannelsFields = RelayChannelsFields()


class Gain(BaseModel):
    gain_ul: float = 25
    gain_dl: float = 50


class FrequencyOffset(BaseModel):
    frequency_offset_ul: float = 0


class Attenuation(BaseModel):
    attenuation_ul: Optional[float] = None
    attenuation_dl: float = 0


class Delay(BaseModel):
    delay_ul: float = 0
    delay_dl: float = 0


class ServiceChannelsFields(BaseModel):
    gain: Gain = Gain()
    frequency_offset: FrequencyOffset = FrequencyOffset()
    attenuation: Optional[Attenuation] = None
    delay: Optional[Delay] = None
    bs_power: float = 40
    bandwidth: float = 10


class ServiceSubChannels(BaseModel):
    enabled_arfcn: Optional[bool] = False
    enabled_earfcn: Optional[bool] = None
    earfcn: float = 0
    arfcns: List[float] = [0, 0, 0, 0]


class ServiceChannels(BaseModel):
    enabled: Optional[bool] = False
    editable: Optional[bool] = False
    frequency: Optional[float]= 1800
    fields: ServiceChannelsFields = ServiceChannelsFields()
    service_subchannels: Optional[ServiceSubChannels] = None


class BandWidth(BaseModel):
    bandwidth_ul: float = 10


class SubchannelsFields(BaseModel):
    bandwidth: BandWidth = BandWidth()
    frequency_offset: FrequencyOffset = FrequencyOffset()


class Subchannels(BaseModel):
    enabled: Optional[bool] = False
    fields: SubchannelsFields = SubchannelsFields()


class Arfsn(BaseModel):
    min: float = 0
    max: float = 0


class ChannelsConfiguration(BaseModel):
    block_mode: BlockMode = BlockMode.WB
    auto_gain_enabled: bool = False
    carrier_frequency: List[CarrierFrequency] = [CarrierFrequency(), CarrierFrequency()]
    relay_channels: List[RelayChannels] = [RelayChannels(), RelayChannels()]
    service_channels: List[ServiceChannels] = [ServiceChannels(), ServiceChannels(), ServiceChannels(), ServiceChannels()]
    subchannels: List[Subchannels] = [Subchannels(), Subchannels(), Subchannels(), Subchannels()]
    arfsn: Arfsn = Arfsn()
